package com.offcn.dycommon.response;

import com.offcn.dycommon.enums.ResponseCodeEnum;

/**
 * @Auther: yao
 * @Date: 2020/10/22 14:04
 * @Description:   //返回响应的封装类
 */
public class AppResponse<T> {

    private Integer code;
    private String msg;
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //响应成功返回的信息
    public static<T> AppResponse<T> ok(T data){
        AppResponse response = new AppResponse();
        response.setCode(ResponseCodeEnum.SUCCESS.getCode());
        response.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        response.setData(data);
        return response;
    }

    //响应失败返回信息
    public static<T> AppResponse<T> fail(T data){
        AppResponse response = new AppResponse();
        response.setCode(ResponseCodeEnum.FAIL.getCode());
        response.setMsg(ResponseCodeEnum.FAIL.getMsg());
        response.setData(data);
        return response;
    }
}
